package com.nanjing.demo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


/**
 * @author dubiao
 * @date 2020/3/21
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    /**
     * 配置Api应用
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.nanjing.demo.controller"))
            .paths(PathSelectors.any())
            .build()
            .apiInfo(getApiInfo());
    }

    /**
     * 创建访问Api的基本信息（这些基本信息会展现在文档页面中）
     * 访问地址：http://localhost:port/swagger-ui.html
     */
    private ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
            .title("接口文档")
            .description("方便调试")
            .contact(new Contact("dubiao", "http://www.qq.com/", "dubiaoyes@foxmail.com"))
            .version("1.0")
            .build();
    }
}


